import 'dart:io';

import 'package:dio/dio.dart';
import 'package:whale/pages/watch/main/utils/DateUtils.dart';

import 'http_man.dart';
import 'result_data.dart';
import 'urlpath.dart';

class Api {
  //登录
  static Future<NetBaseReponse> login(Map<String, dynamic> param) {
    return HttpMan.instance.post(UrlPath.login, args: param);
  }

  //登录
  static Future<NetBaseReponse> smslogin(Map<String, dynamic> param) {
    return HttpMan.instance.post(UrlPath.smsLogin, args: param);
  }

  //发送验证码
  static Future<NetBaseReponse> sendCode(Map<String, dynamic> param) {
    return HttpMan.instance.post(UrlPath.sendCode, args: param);
  }
}

extension HomeApi on Api {
  static Future<NetBaseReponse> getNewDocSum() {
    return HttpMan.instance.get(UrlPath.getNewDocSum, args: {
      'reportType': "政策措施,招标采购",
    });
  }

  static Future<NetBaseReponse> pageDoc({
    required String type,
  }) {
    return HttpMan.instance.get(UrlPath.pageDoc, args: {
      'reportType': type,
      'size': 5,
      'current': 1,
    });
  }

  static Future<NetBaseReponse> pageDocByTypeList() {
    return HttpMan.instance.post(UrlPath.pageDocByReportTypeList, args: {
      'reportTypeList': ["政策措施", "招标采购"],
      'size': 6,
      'current': 1,
    });
  }
}

class WatchApi extends Api {
  static Future<NetBaseReponse> trendData(String reportType,
      {String? startTime, String? endTime}) {
    return HttpMan.instance.get(UrlPath.trendAnalysis, args: {
      'problemType': '全部',
      'reportType': reportType,
      'startTime': startTime ?? DateUtils.getMonthDateStr(),
      'endTime': endTime ?? DateUtils.getNowDateStr(),
    });
  }

  static Future<NetBaseReponse> trendData30(String reportType,
      {String? startTime, String? endTime}) {
    return HttpMan.instance.get(UrlPath.trendAnalysis, args: {
      'problemType': '全部',
      'reportType': reportType,
      'startTime': startTime ?? DateUtils.get30DateStr(),
      'endTime': endTime ?? DateUtils.getNowDateStr(),
    });
  }

  static Future<NetBaseReponse> getIllDocSumByRiskLevel(String reportType,
      {String? startTime, String? endTime}) {
    return HttpMan.instance.get(UrlPath.getIllDocSumByRiskLevel, args: {
      'reportType': reportType,
      'startTime': startTime ?? DateUtils.getMonthDateStr(),
      'endTime': endTime ?? DateUtils.getNowDateStr(),
    });
  }

  static Future<NetBaseReponse> getIllDocByProblemType(String reportType,
      {String? startTime, String? endTime}) {
    return HttpMan.instance.get(UrlPath.getIllDocByProblemType, args: {
      'reportType': reportType,
      'startTime': startTime ?? DateUtils.getMonthDateStr(),
      'endTime': endTime ?? DateUtils.getNowDateStr(),
    });
  }
}

class MeApi extends Api {
  static Future<NetBaseReponse> versionUpdate() {
    return HttpMan.instance.get(UrlPath.checkUpdate);
  }

  static Future<NetBaseReponse> cloudCOLLECT(String reportType) {
    return HttpMan.instance.post(UrlPath.file_page,
        args: {'current': 1, 'size': 20, 'reportType': reportType});
  }

  static Future<NetBaseReponse> saveGsFiles(dynamic map) {
    return HttpMan.instance.post(UrlPath.saveGsFiles, args: map);
  }

  static Future<NetBaseReponse> uploadFiles(String filePath) async {
    return HttpMan.instance.upload(
      UrlPath.uploadFiles,
      data: FormData.fromMap({'files': await MultipartFile.fromFile(filePath)}),
    );
  }

  static Future<NetBaseReponse> getMeInfo(String userId) async {
    return HttpMan.instance.post(
      UrlPath.userInfo,
      args: {
        'oneParam': userId,
        'tenantId': 'TENANT_GZ',
      },
    );
  }
}

extension MeansApi on Api {
  static Future<NetBaseReponse> postDocDetail({
    required String id,
    required String type,
  }) {
    return HttpMan.instance.post(UrlPath.doc_detail, args: {
      'id': id,
      'reportType': type,
    });
  }

  static Future<NetBaseReponse> getDocList({
    String? id,
    required String type,
    String? keywords,
    Map<String, String>? params,
    int pageIndex = 1,
  }) {
    Map<String, dynamic> args = {};
    args.addAll(params ?? {});
    args.addAll({
      'hasProblem': '-1',
      'reportType': type,
      'keywords': keywords ?? '',
      'current': pageIndex,
      'size': 10,
    });
    return HttpMan.instance.get(UrlPath.doc_list, args: args);
  }

  static Future<NetBaseReponse> postDocFilters() {
    return HttpMan.instance.post(UrlPath.doc_filters);
  }

  static Future<NetBaseReponse> postDocSearch({
    required String keywords,
    required String reportType,
  }) {
    return HttpMan.instance.get(UrlPath.doc_list, args: {
      'keywords': keywords,
      'reportType': reportType,
    });
  }

  ///查看公告
  static Future<NetBaseReponse> postDocNoti({
    required String id,
  }) {
    return HttpMan.instance.post(UrlPath.doc_noti, args: {
      'id': id,
    });
  }
}
